package com.minminaya.source;

public class Algorithm_10 {

    public static class ListNode {
        int value;
        ListNode next;
    }

    /**
     * 返回链表的头节点
     */
    public static ListNode deleteNode(ListNode head, ListNode toBeDeleted) {
        //输入有空
        if (head == null || toBeDeleted == null) {
            return null;
        }


        if (head == toBeDeleted) {
            //如果是头结点
            return head.next;
        }

        if(toBeDeleted.next == null){
            //如果是tail节点
            ListNode temp = head;
            while (temp.next != toBeDeleted){
                temp = temp.next;
            }
            temp.next = null;
        }else{
            //将下一个节点换到本身来
            toBeDeleted.value = toBeDeleted.next.value;
            toBeDeleted.next = toBeDeleted.next.next;
        }
        return head;
    }

}
